home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Files / PBDTGetAppl / Source / SlimFunctions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-07  |  2.5 KB  |  154 lines  |  [TEXT/KAHL]

  1. /*
  2.     9-30-92  • Brigham Stevens
  3.     --------------------------
  4.  
  5.     This is for sticking in test code that you want to run
  6.     in response to menu commands.
  7. */
  8.  
  9. #include "MenuDispatch.h"
  10. #include <Files.h>
  11.  
  12.  
  13. pstrcat(s1, s2)
  14. register char *s1, *s2;
  15. {
  16.     register char *p;
  17.     register short len, i;
  18.     
  19.     if (*s1+*s2<=255) 
  20.     {
  21.         p = *s1 + s1 + 1;
  22.         *s1 += (len = *s2++);
  23.     }
  24.     else 
  25.     {
  26.         *s1 = 255;
  27.         p = s1 + 256 - (len = *s2++);
  28.     }
  29.     for (i=len; i; --i) *p++ = *s2++;
  30. }
  31.  
  32.  
  33.  
  34. void DisplayStuff(DTPBPtr    dtp)
  35. {
  36.     Str255    msg = "\pFound It!\rName of Appl is: ";
  37.     
  38.     pstrcat(msg, dtp->ioNamePtr);
  39.     
  40.     Msg(msg);
  41. }
  42.  
  43.  
  44. void SlimFunction1()
  45. {
  46.     DTPBPtr    dtp;
  47.     WDPBPtr    gvp;
  48.     short    diskRefNum;
  49.     short    dbRef;
  50.     short    err;
  51.     Str255    name;
  52.     
  53.     
  54.     /*    Get the vRef of the disk with the desktop DB we want */
  55.     gvp = NewPtrClear(sizeof(WDPBRec));
  56.     if(!gvp) {
  57.         ErrMsg("\pfail: getVolpb = NewPtrClear(sizeof(WDPBRec));");
  58.         return; 
  59.     }
  60.     
  61.     err = PBHGetVol(gvp,false);
  62.     if(err) {
  63.         ErrMsg("\perr = PBHGetVol(gvp,false);");
  64.         return; 
  65.     }
  66.     diskRefNum = gvp->ioVRefNum;
  67.     DisposePtr(gvp);
  68.     
  69.     dtp = NewPtrClear(sizeof(DTPBRec));
  70.     if(!dtp) {
  71.         ErrMsg("\pfail: dtp = NewPtrClear(sizeof(DTPBRec));");
  72.         return;
  73.     }
  74.     
  75.     /*  Get the ref num of the DB you want to munge */
  76.     /*  either specify the name of the volume */
  77.     /* or use a vRefNum */
  78.     /* We are using the same volume as the application */
  79.     
  80.     dtp->ioNamePtr = name;
  81.     dtp->ioVRefNum = diskRefNum;
  82.     
  83.     err = PBDTGetPath(dtp);
  84.     if(err) {
  85.         ErrMsgCode("\pfail: err = PBDTGetPath(dtp);",err);
  86.         return;
  87.     }
  88.     
  89.     dbRef = dtp->ioDTRefNum;
  90.     DisposePtr(dtp);
  91.  
  92.     /* re-initialize our parameter block */
  93.     /* this makes sure all fields start at ZERO */
  94.     dtp = NewPtrClear(sizeof(DTPBRec));
  95.     if(!dtp) {
  96.         ErrMsg("\pfail: dtp = NewPtrClear(sizeof(DTPBRec)) [2];");
  97.         return; 
  98.     }
  99.     
  100.     /* Setup for the PBDTGetAPPL call */
  101.     /* the GetCreator call just gets an OSType */
  102.     
  103.     dtp->ioNamePtr = name;
  104.     dtp->ioDTRefNum = dbRef;
  105.     dtp->ioIndex = 0;
  106.     if(GetCreator(&dtp->ioFileCreator) == 1) {
  107.         err = PBDTGetAPPL(dtp,false);
  108.         if(err)
  109.             if(err == afpItemNotFound)
  110.                 Msg("\pThe Creator you are seaking is unavailable.");
  111.             else
  112.                 ErrMsgCode("\pfail: err = PBDTGetAPPL(dtp,false);",err);
  113.         else 
  114.             DisplayStuff(dtp);
  115.     }
  116.     
  117.     DisposePtr(dtp);
  118. }
  119.  
  120. void SlimFunction2()
  121. {
  122.     SysBeep(5);
  123. }
  124.  
  125.  
  126. void SlimFunction3()
  127. {
  128.     SysBeep(5);
  129. }
  130.  
  131.  
  132. void SlimFunction4()
  133. {    
  134.     SysBeep(5);
  135. }
  136.  
  137.  
  138. void ChooseSlim(short item)
  139. {
  140.     switch(item) {
  141.         case SLIM_1    :    SlimFunction1();
  142.                             break;
  143.         case SLIM_2    :    SlimFunction2();
  144.                             break;
  145.         case SLIM_3    :    SlimFunction3();
  146.                             break;
  147.         case SLIM_4    :    SlimFunction4();
  148.                             break;
  149.         default:            break;
  150.     }
  151. }
  152.  
  153.  
  154.